<template>
  <div class="rolezr">
    <div class="header">
      <table>
        <tr>
          <td><span>UID：</span></td>
          <td style="margin-left:-35px;">
            <el-input v-model="uid" placeholder="请输入玩家uid"></el-input>
          </td>
          <td>
            <el-button type="primary" @click="search()">查询</el-button>
          </td>
        </tr>
      </table>
    </div>
    <div class="content">
      <el-main v-loading="loading">
        <el-table
          border
          :fit="true"
          :header-cell-style="{
            color: '#333',
            fontFamily: 'MicrosoftYaHeiUI',
            fontWeight: 500,
            fontSize: '16px',
          }"
          :data="tableData.slice((currentPage - 1) * pageSize,currentPage * pageSize)"
        >
          <el-table-column 
            prop="uid" 
            sortable 
            label="uid"
          ></el-table-column>
          <el-table-column
            prop="role_id"
            sortable
            label="龙(role_id)"
          ></el-table-column>
          <el-table-column
            prop="in_crystal"
            sortable
            label="是否在水晶内"
          ></el-table-column>
          <el-table-column
            prop="role_level"
            sortable
            label="等级"
          ></el-table-column>
          <el-table-column
            prop="campType"
            sortable
            label="品阶"
          ></el-table-column>
          <el-table-column
            prop="role_power"
            sortable
            label="战力"
          ></el-table-column>
          <el-table-column
            prop="percentage_of_times"
            sortable
            label="次数百分比"
          ></el-table-column>
        </el-table>
        <pageNation
          :total="tableData.length"
          :page-size="pageSize"
          @pageChange="pageChange"
          :page_index="currentPage"
        />
      </el-main>
    </div>
  </div>
</template>
<script>
import pageNation from "../../components/pagenation/pageNation";
export default {
  name: "RoleZR",
  components: { pageNation },
  data() {
    return {
      tableData: [],
      uid: "",
      currentPage: 1, //当前页数
      pageSize: 10, //每页的数据
      loading: false,
    };
  },
  methods: {
    //分页
    pageChange(item) {
      this.currentPage = item.page_index;
      this.pageSize = item.page_limit;
    },
    //查询
    search() {
      if (this.uid == "") {
        this.$message({
          type: "warning",
          message: "请输入需要查询的uid",
        });
        return;
      } else {
        this.loading = true;
        this.$http.post("/api/role/rolezr", { uid: this.uid }).then((res) => {
          if (res.data.result.length > 0) {
            this.tableData = res.data.result;
            this.loading = false;
          } else {
            this.$message({ type: "warning", message: "没有对应的数据" });
            this.loading = false;
            this.uid = "";
            return;
          }
        });
      }
    },
  },
};
</script>
<style scoped>
.rolezr {
  width: 100%;
  height: auto;
  background-color: #fff;
}
.rolezr td {
  padding: 18px;
  font-size: 14px;
  display: flex;
  float: left;
}
</style>
